#include "stdafx.h"
#include "Shaders.h"

int Shaders::Init(char * fileVertexShader, char * fileFragmentShader)
{
	vertexShader = esLoadShader(GL_VERTEX_SHADER, fileVertexShader);

	if ( vertexShader == 0 )
		return -1;

	fragmentShader = esLoadShader(GL_FRAGMENT_SHADER, fileFragmentShader);

	if ( fragmentShader == 0 )
	{
		glDeleteShader( vertexShader );
		return -2;
	}

	program = esLoadProgram(vertexShader, fragmentShader);

	//finding location of uniforms / attributes
	//ATTRIBUTE
	a_positon = glGetAttribLocation(program, "a_posL");
	a_uv = glGetAttribLocation(program, "a_uv");
	a_normal = glGetAttribLocation(program, "a_norL");
	a_binormal = glGetAttribLocation(program, "a_binorL");
	a_tangent = glGetAttribLocation(program, "a_tengL");
	u_World = glGetUniformLocation(program, "m_World");
	u_MatrixMVP = glGetUniformLocation(program, "m_MatrixMVP");
	u_Camera = glGetUniformLocation(program, "m_Camera");
	u_texture = glGetUniformLocation(program, "u_texture");
	
	//UNIFORM
	uniformA0=glGetUniformLocation(program,"a0");
	uniformA1=glGetUniformLocation(program,"a1");
	uniformA2=glGetUniformLocation(program,"a2");
	uniformColorText = glGetUniformLocation(program, "color");

	uniformLightDirect=glGetUniformLocation(program,"u_lightMainDirect");
	uniformLightSpecular=glGetUniformLocation(program,"u_lightSpecular");
	uniformLightAmbient=glGetUniformLocation(program,"u_lightAmbient");
	uniformLightColor=glGetUniformLocation(program,"u_lightColor");
	uniformLightPosition=glGetUniformLocation(program,"u_lightPosition");
	uniformCameraPosition=glGetUniformLocation(program,"u_camPosition");
	uniformObjectWorld=glGetUniformLocation(program,"u_W");
	u_MatrixMVP=glGetUniformLocation(program,"m_MatrixMVP");
	timeUniform=glGetUniformLocation(program,"u_time");
	cubeSampler=glGetUniformLocation(program,"u_samplerCubeMap");
	//dirtSampler=glGetUniformLocation(program,"u_texture_dirt");
	//grassSampler=glGetUniformLocation(program,"u_texture_grass");
	//rockSampler=glGetUniformLocation(program,"u_texture_rock");
	//blendSampler=glGetUniformLocation(program,"u_blendmap");
	samples[0] = glGetUniformLocation(program, "u_blendmap");
	samples[1] = glGetUniformLocation(program, "u_texture_grass");
	samples[2] = glGetUniformLocation(program, "u_texture_dirt");
	samples[3] = glGetUniformLocation(program, "u_texture_rock");
	samples[4] = glGetUniformLocation(program, "u_texture_water");

	return 0;
}

Shaders::~Shaders()
{
	glDeleteProgram(program);
	glDeleteShader(vertexShader);
	glDeleteShader(fragmentShader);
}